package router

import (
	"octopus/user/app/command"
	"octopus/user/app/query"
	"time"

	"octopus/hextech/message"

	"github.com/gin-gonic/gin"
)

func HTTP(engine *gin.Engine) {
	engine.Use(gin.Recovery())
	versionGroup := engine.Group("/v1")
	healthGroup := versionGroup.Group("/health")
	{

		healthGroup.GET("", func(ctx *gin.Context) {
			type health struct {
				TIME string `json:"time"`
			}
			var myHealth = health{}
			myHealth.TIME = time.Now().Format("2006-01-02 15:04:05")
			message.WriteResponse(ctx, nil, myHealth)
		})
	}

	userRouter := versionGroup.Group("/user")
	{
		userRouter.POST("/login", command.Login)
		userRouter.POST("/create", command.CreateUser)
		userRouter.GET("/info", query.UserInfo)
	}
}
